﻿/*

  The contents of this file are subject to the Mozilla Public License Version
  1.1 (the "License"); you may not use this file except in compliance with
  the License. You may obtain a copy of the License at 
  
           http://www.mozilla.org/MPL/ 
  
  Software distributed under the License is distributed on an "AS IS" basis,
  WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  for the specific language governing rights and limitations under the License. 
  
  The Original Code is LunAS Library.
  
  The Initial Developer of the Original Code is
  ALCARAZ Marc (aka eKameleon)  <ekameleon@gmail.com>.
  Portions created by the Initial Developer are Copyright (C) 2004-2010
  the Initial Developer. All Rights Reserved.
  
  Contributor(s) :
  Nicolas Surian (aka NairuS) <nicolas.surian@gmail.com> 
*/

package examples 
{
    import graphics.Align;
    import graphics.Direction;
    import graphics.FillStyle;
    import graphics.LineStyle;
    import graphics.geom.EdgeMetrics;
    
    import lunas.display.bar.SimpleProgressbar;
    import lunas.events.ComponentEvent;
    
    import flash.display.Sprite;
    import flash.display.StageScaleMode;
    import flash.events.KeyboardEvent;
    import flash.filters.DropShadowFilter;
    import flash.ui.Keyboard;
    
    public class ExampleSimpleProgressbar extends Sprite 
    {
        public function ExampleSimpleProgressbar()
        {
            
            stage.scaleMode = StageScaleMode.NO_SCALE ;
            
            bar = new SimpleProgressbar() ;
            
            bar.addEventListener( ComponentEvent.CHANGE , change ) ;
            
            bar.x = 50 ;
            bar.y = 50 ;
            bar.position = 50 ;
            
            addChild(bar) ;
            
            var shadow:DropShadowFilter = new DropShadowFilter( 1, 45, 0x000000, 0.6, 6, 6, 1, 6) ;
            bar.filters = [ shadow  ] ;
            
            stage.addEventListener( KeyboardEvent.KEY_DOWN , keyDown ) ;
            
            trace("Press Keyboard.LEFT or Keyboard.RIGHT or Keyboard.SPACE  or other keyboard touch to test this example, or Keyboard.INSERT to reset the example.") ;
        }
        public var bar:SimpleProgressbar ;
        
        public function change( e:ComponentEvent ):void
        {
            trace( e.type + " : " + bar.position ) ;
        }
        
        public function keyDown( e:KeyboardEvent ):void
        {
            var code:uint = e.keyCode ;
            trace(code) ;
            switch( code )
            {
                case Keyboard.LEFT :
                {
                    bar.position -= 10 ;
                    break ;
                }
                case Keyboard.RIGHT :
                {
                    bar.position += 10 ;
                    break ;
                }
                case Keyboard.UP :
                {
                    bar.minimum = 20  ;
                    bar.maximum = 200 ;
                    break ;
                }
                case Keyboard.SPACE :
                {
                    bar.lock() ;
                    bar.align               = Align.CENTER ; // Align.LEFT or Align.RIGHT or Align.CENTER
                    bar.direction           = Direction.HORIZONTAL ;
                    bar.backgroundFillStyle = new FillStyle( 0xB5C7CA , 1 ) ;
                    bar.backgroundLineStyle = new LineStyle( 2 , 0xFFFFFF , 1 ) ;
                    bar.barFillStyle        = new FillStyle( 0x921085 , 1 ) ;
                    bar.barLineStyle        = new LineStyle( 1 , 0x6A9195, 1 ) ;
                    bar.border              = new EdgeMetrics(2, 2, 2, 2) ;
                    bar.unlock() ;
                    bar.setSize( 200, 8 ) ;
                    break ;
                }
                case Keyboard.INSERT : 
                {
                    bar.lock() ;
                    bar.align               = Align.LEFT ; // Align.LEFT or Align.RIGHT or Align.CENTER
                    bar.direction           = Direction.HORIZONTAL ;
                    bar.backgroundFillStyle = new FillStyle( 0xFFFFFF , 1 ) ;
                    bar.backgroundLineStyle = new LineStyle( 1 , 0xA2A2A2 , 1 ) ;
                    bar.barFillStyle        = new FillStyle( 0xFF0000 , 1 ) ;
                    bar.barLineStyle        = null ;
                    bar.border              = new EdgeMetrics() ;
                    bar.unlock() ;
                    bar.setSize( 150, 6 ) ;
                    break ;
                }
                default :
                {
                    bar.direction = ( bar.direction == Direction.VERTICAL ) ? Direction.HORIZONTAL : Direction.VERTICAL ;
                    if ( bar.direction == Direction.VERTICAL )
                    {
                        bar.setSize( 8, 500 ) ;
                    }
                    else
                    {
                        bar.setSize( 500, 8 ) ;
                    }
                }
            }
        }
    }
}
